#include "StudentRegister.h";
#include <sstream>
#include "BaseMenu.h"


int main3_1( void );
int main3_2( void );
int main3_3( void );
int main3_4( void );
int main3_5_6( void );

int main4( void );


int main( void )
{
	// Since changes were made to class Student, main 3_1 through 3_5_6 no longer works. Added 'id' to student.

	//main3_1();
	//main3_2();
	//main3_3();
	//main3_4();
	//main3_5_6();
	main4();
	cin.get();
	return 0;
}


int main3_1( void )
{
	cout << "Main3_1():" << endl;

	Student a;

	cout << "Set info on student:" << endl;
	cout << "Set first name to Kalle" << endl;
	a.SetFirstName("Kalle");
	cout << "Set last name to Anka" << endl;
	a.SetLastName("Anka");
	cout << "Set enrollment year to 1970" << endl;
	a.SetEnrollmentYeat(1970);

	cout << "Get info on student:" << endl;
	cout << "First Name: " << a.GetFirstName() << endl;
	cout << "Last Name: " << a.GetLastName() << endl;
	cout << "Enrollment Year: " << a.GetEnrollmentYear() << endl;

	return 0;
}

int main3_2( void )
{
	cout << "Main3_2():" << endl;

	Student a;

	cout << "Read():" << endl;
	a.Read();

	cout << "Write():" << endl;
	a.Write();

	cin.get();
	return 0;
}

int main3_3( void )
{
	cout << "Main3_3():" << endl;

	Student a;
	istringstream iss("(firstName,lastName,enrollmentYear) = (Kalle,Anka,1970)");

	cout << "Enter data on student:" << endl;

	iss >> a;

	cout << "Print data on student:" << endl;
	cout << a;


	cin.get();
	return 0;
}

int main3_4( void )
{
	cout << "Main3_4():" << endl;

	StudentRegister sr;
	Student a("Kalle", "Anka", 1970);
	Student b("Niclas", "Stromberg", 2009);

	cout << "Add Student a and b to registry:" << endl;

	sr.Add(a);
	sr.Add(b);

	cout << "The registry contains:" << endl;
	cout << sr.List() << endl;



	cin.get();
	return 0;
}

int main3_5_6( void )
{
	cout << "Main3_5_6():" << endl;


	cout << "Create registry and two students, add students to registry" << endl;
	StudentRegister sr;
	Student a("Kalle", "Anka", 1970);
	Student b("Niclas", "Stromberg", 2009);
	sr.Add(a);
	sr.Add(b);

	cout << "The registry contains:" << endl;
	cout << sr.List() << endl;

	cout << "Save registry to file 'file.txt' and clear the registry:" << endl;

	sr.WriteToFile("file.txt");
	sr.Clear();

	cout << "The registry contains:" << endl;
	cout << sr.List() << endl;

	cout << "Read from file 'file.txt':" << endl;

	sr.ReadFromFile("file.txt");

	cout << "The registry contains:" << endl;
	cout << sr.List() << endl;

	return 0;

}

int main4( void )
{
	cout << "Main4():" << endl;
	BaseMenu mainMenu;
	StudentRegister sr;

	while( !mainMenu.GetExitMenu() )
	{
		mainMenu.Show();
		mainMenu.MakeChoice();
		switch (mainMenu.GetChoice())
		{
		case 1:
			sr.AddStudent();
			cin.get();
			break;
		case 2:
			sr.RemoveStudent();
			cin.get();
			break;
		case 3:
			int pos;
			pos = sr.SelectStudent();
			if( pos == 0 )
				break;
			sr.registry[pos-1].AddCourse();
			cin.get();
			break;
		case 4:
			pos = sr.SelectStudent();
			if( pos == 0 )
				break;
			int course;
			course = sr.registry[pos-1].SelectCourse();
			sr.registry[pos-1].courses[course-1].AddResult();
			cin.get();
			break;
		case 5:
			sr.WriteToFile("save4.txt");
			cin.get();
			break;
		case 6:
			sr.ReadFromFile("save4.txt");
			break;
		default:
			break;
		}
	}

	return 0;
}